package com.lyf.scm.plan.domain.repository;

import com.lyf.scm.plan.api.dto.DirectlyStoreDTO;
import com.lyf.scm.plan.api.dto.DirectlyStoreQueryDTO;
import com.lyf.scm.plan.domain.convertor.DirectlyStoreConvertor;
import com.lyf.scm.plan.domain.convertor.DirectlyStoreSelectConvertor;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyStoreInDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyStoreUpDO;
import com.lyf.scm.plan.insfrastructure.db.mapper.DirectlyStoreMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * description:
 *
 * @author: haodong
 * @data: 2020/8/29 17:18
 */
@Service
public class DirectlyStoreRepository {

    @Resource
    private DirectlyStoreMapper directlyStoreMapper;

    @Resource
    private DirectlyStoreConvertor directlyStoreConvertor;
    @Resource
    private DirectlyStoreSelectConvertor directlyStoreSelectConvertor;


    /**
     * 根据分页后结果参数多条件查询
     *
     * @param directlyStoreQueryDTO
     * @return
     */
    public List<DirectlyStoreDTO> listBySelective(DirectlyStoreQueryDTO directlyStoreQueryDTO) {
        return directlyStoreConvertor.doToDTO(directlyStoreMapper.listBySelective(directlyStoreConvertor.directlyStoreQueryToDO(directlyStoreQueryDTO)));
    }


    public List<DirectlyStoreDTO> listByStoreCode(List<String> storeCodeList) {
        return directlyStoreConvertor.doToDTO(directlyStoreMapper.listByStoreCode(storeCodeList));
    }

    public List<DirectlyStoreDTO> listAllInfo(DirectlyStoreQueryDTO directlyStoreQueryDTO) {
        return directlyStoreConvertor.doToDTO(directlyStoreMapper.listAllInfo(directlyStoreConvertor.directlyStoreQueryToDO(directlyStoreQueryDTO)));
    }

    public Integer updateStatus(List<DirectlyStoreQueryDTO> storeQueryDTOS) {
        return directlyStoreMapper.updateStatus(directlyStoreConvertor.directlyStoreQueryToDOS(storeQueryDTOS));
    }

    public Integer updateCancelStatus(List<DirectlyStoreDTO> storeDTOS) {
        return directlyStoreMapper.updateStatus(directlyStoreConvertor.dtoToDO(storeDTOS));
    }

    public List<DirectlyStoreDTO> listAllInfoByTime(Date startTime, Date endTime) {
        return directlyStoreConvertor.doToDTO(directlyStoreMapper.listAllInfoByTime(startTime, endTime));
    }

    public Integer updateStatusAndLastConfirmQty(List<DirectlyStoreDTO> storeDTOS) {
        return directlyStoreMapper.updateStatusAndLastConfirmQty(directlyStoreConvertor.dtoToDO(storeDTOS));
    }

    /**
     *
     *
     * @param code
     * @param startDate
     * @param endDate
     * @return {@link List<DirectlyStoreUpDO>}
     **/
    public List<DirectlyStoreDTO> listAllByStoreAndDate(List<String> code, Date startDate, Date endDate) {
        return directlyStoreConvertor.doToDTO(directlyStoreMapper.listAllByStoreAndDate(code, startDate, endDate));
    }

    /**
     * 根据门店和日期获取所有需要更新的数据（默认为13天数据，今日起）
     *
     * @param code
     * @param startDate
     * @param endDate
     * @return {@link List<DirectlyStoreUpDO>}
     **/
    public List<DirectlyStoreInDO> listInByStoreAndDate(String code, Date startDate, Date endDate) {
        return directlyStoreMapper.listInByStoreAndDate(code, startDate, endDate);
    }
    /**
     * 根据门店和日期获取所有需要更新的数据（默认为13天数据，今日起）
     *
     * @param code
     * @param startDate
     * @param endDate
     * @return {@link List<DirectlyStoreUpDO>}
     **/
    public List<DirectlyStoreUpDO> listUpByStoreAndDate(String code, Date startDate, Date endDate) {
        return directlyStoreMapper.listUpByStoreAndDate(code, startDate, endDate);
    }
    /**
     * 批量新增
     *
     * @param directlyStoreInDOs
     * @return void
     **/
    public void batchInsert(List<DirectlyStoreInDO> directlyStoreInDOs) {
        directlyStoreMapper.batchInsert(directlyStoreInDOs);
    }

    public void delete(String opSign){
        directlyStoreMapper.delete(opSign);
    }
    /**
     * 删除当前日期之后的所有数据
     *
     * @param dayStartDate
     * @return void
     **/
    public void batchDeleteByStartDate(String storeCode,Date dayStartDate) {
        directlyStoreMapper.batchDeleteByStartDate(storeCode,dayStartDate);
    }

    public void rmByIds(List<Long> ids) {
        directlyStoreMapper.rmByIds(ids);
    }

    public void upByIds(List<DirectlyStoreUpDO> list) {
        directlyStoreMapper.upByIds(list);
    }

    public void deleteByOpSign(String opSign) {
        directlyStoreMapper.deleteByOpSign(opSign);
    }

    public List<DirectlyStoreDTO> listByCondition(DirectlyStoreDTO directlyStore) {
        return directlyStoreConvertor.doToDTO(directlyStoreMapper.listByCondition(directlyStoreSelectConvertor.dtoToDO(directlyStore)));
    }
}
